
//布局东
$(function () {

    //响应集合函数对象
    var cmdObj = {

        //输入框积分清空
        remove:function () {

           $("#number_input").textbox("clear");

        },
        commit:function () {
            var number = 0- $("#number_input").textbox("getValue");
            if(!$("#checkOut").is(':checked')&&!$("#checkIn").is(':checked')){
                $.messager.alert('温馨提示','请选择充值或者扣除');
            }
            else if(!number){
                $.messager.alert('温馨提示','请输入积分数量');
            }else{
                if($("#checkOut").is(':checked') ){
                    alert("减少"+number);
                    //修改会员积分
                    var memberRow = $("#member_datagrid").datagrid("getSelected");
                    var memId = memberRow.id;
                    //删除ajax请求
                    $.post("/member/integralUpdate?",{id:memId,number:number},function (data) {
                        if(!data.success){
                            $.messager.alert('温馨提示',data.msg);
                        }else{
                            $.messager.alert('温馨提示',"扣除成功");
                            gift_datagrid.datagrid("load");
                            $("#member_datagrid").datagrid("reload");
                        }
                    })

                    //更新兑换记录表
                    //ajax请求
                    $.post("/pointBuy/save?",{id:memId,number:number},function (data) {
                        if(!data.success){
                            $.messager.alert('温馨提示',data.msg);
                        }else{
                            $.messager.alert('温馨提示',"记录已生成");
                            $("#exchangegift_datagrid").datagrid("load");
                            $("#member_datagrid").datagrid("reload");
                        }
                    })

                }else{
                    number = 0-number;
                    //修改会员积分
                    var memberRow = $("#member_datagrid").datagrid("getSelected");
                    var memId = memberRow.id;
                    //删除ajax请求
                    $.post("/member/integralUpdate?",{id:memId,number:number},function (data) {
                        if(!data.success){
                            $.messager.alert('温馨提示',data.msg);
                        }else{
                            $.messager.alert('温馨提示',"充值成功");
                            gift_datagrid.datagrid("load");
                            $("#member_datagrid").datagrid("reload");
                        }
                    })

                    //更新兑换记录表
                    //ajax请求
                    $.post("/pointBuy/save?",{id:memId,number:number},function (data) {
                        if(!data.success){
                            $.messager.alert('温馨提示',data.msg);
                        }else{
                            $.messager.alert('温馨提示',"记录已生成");
                            $("#exchangegift_datagrid").datagrid("reload");
                            $("#member_datagrid").datagrid("reload");

                        }
                    })
                }

            }


        }

    };

    //调用
    $("a[data-cmd]").click(function(){

        var cmd = $(this).data("cmd");
        cmdObj[cmd]();
    })
    //end


    //初始化时两个选择框未被选
    $("#checkIn").prop("checked",false);
    $("#checkOut").prop("checked",false);
    //end
    //绑定事件
    $("#checkIn").change(function() {
        if($("#checkOut").is(':checked') ){
            $("#checkOut").prop("checked",false);
        }
    });
    $("#checkOut").change(function() {
        if($("#checkIn").is(':checked') ){
            $("#checkIn").prop("checked",false);
        }
    });
    //end

});







//布局中
$(function () {
    //定义常用easyui对象
    var member_datagrid = $("#member_datagrid");

    //end

    //初始化礼品列表 gift_datagrid
    member_datagrid.datagrid({
        title:"会员列表",
        url:'/member/list',
        fitColumns:true,
        fit:true,
        singleSelect:true,
        striped:true,
        toolbar: '#tb',
        columns:[[
            {field:'memberName',title:'会员名',width:100},
            {field:'balance',title:'储值',width:100,align:'right'},
            {field:'tel',title:'电话',width:100,align:'right'},
            {field:'grade',title:'等级',width:100,align:'right',formatter: function(value,row,index){
            if(value){
                return value.name;
            }else{
                return "无等级";
            }

            }
            }
        ]],

        //数据加载完成之后
        onLoadSuccess:function () {

            var rows = $("#member_datagrid").datagrid("getRows");


            //西布局会员详细信息列表
            $('#pg').propertygrid({
                showGroup: false,
                scrollbarSize: 0,
                fit:true,
                data: [
                    {"name":"会员姓名","value":rows[0].memberName,"editor":"text"},
                    {"name":"会员等级","value":rows[0].grade.name,"editor":"text"},
                    {"name":"当前积分","value":rows[0].integral,"editor":"text"},
                    {"name":"会员卡号","value":rows[0].memberNumber,"editor":"text"},
                    {"name":"会员余额","value":rows[0].balance,"editor":"text"},
                    {"name":"会员生日","value":rows[0].birthDate,"editor":"text"}

                ]

            });


        },

        onClickRow:function (index,row) {
            //member_datagrid.datagrid("reload");

        //会员点击事件西布局显示详细信息
            $('#pg').propertygrid({
                showGroup: false,
                scrollbarSize: 0,
                fit:true,
                data: [
                    {"name":"会员姓名","value":row.memberName,"editor":"text"},
                    {"name":"会员等级","value":row.grade.name,"editor":"text"},
                    {"name":"当前积分","value":row.integral,"editor":"text"},
                    {"name":"会员卡号","value":row.memberNumber,"editor":"text"},
                    {"name":"会员余额","value":row.balance,"editor":"text"},
                    {"name":"会员生日","value":row.birthDate,"editor":"text"}

                ]

            });

            //会员信息点击事件南布局列表高级查询

                //获取高级查询输入框的文本
                var kw = row.memberNumber;
                if(!kw){

                    return;
                }
            $("#exchangegift_datagrid").datagrid("load",{
                    keyword:kw
                });


            //end

        }
    });
    //end








});

//中间布局会员表高级查询
function query () {
    //获取高级查询输入框的文本
    var kw = $("#keyword").textbox("getValue")
    if(!kw){
        $.messager.alert('温馨提示','请输入关键字');
        return;
    }
    member_datagrid.datagrid("load",{
        keyword:kw
    })
}
//end

//布局南
$(function () {

    //初始化礼品兑换列表 exchangegift_datagrid
    $("#exchangegift_datagrid").datagrid({
        title:"积分充值列表",
        url:'/pointBuy/list',
        fitColumns:true,
        fit:true,
        pagination:true,
        rownumbers:true,
        singleSelect:true,
        striped:true,
        toolbar: '#tb',
        columns:[[
            {field:'id',title:'编号',width:100},
            {field:'memberinfoCardnumber',title:'会员卡号',width:100},
            {field:'memberinfoName',title:'会员名称',width:100,align:'right'},
            {field:'memberinfoGrade',title:'会员等级',width:100,align:'right'},
            {field:'inputType',title:'操作类型',width:100,align:'right'},
            {field:'changePoint',title:'变动数额',width:100,align:'right'},
            {field:'inputUsername',title:'操作人员',width:100,align:'right'},
            {field:'buyDate',title:'充值时间',width:100,align:'right'},
            {field:'remark',title:'备注',width:100,align:'right'}
        ]]
    });
    //end


})





























